package cn.stronglink.oil.map.webmap;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import cn.stronglink.oil.video.RTMPActivity;
import cn.stronglink.oil.video.RTMPActivity2;
import cn.stronglink.oil.video.VideoActivity;
import cn.stronglink.oil.video.VideoListActivity;
import cn.stronglink.oil.widget.MyDialog;

/**
 * Created by Tgb on 2018/8/27.
 */

public class NativeInterface {
    private Context mContext;

    public NativeInterface(Context context) {
        mContext = context;
    }


    @JavascriptInterface
    public void startSpeech() {
        if(mContext instanceof LoadWebMapActivity){
            LoadWebMapActivity ac = (LoadWebMapActivity)mContext;
            ac.startSpeech();
        }
    }

    @JavascriptInterface
    public void exit() {
        if(mContext instanceof LoadWebMapActivity){
            LoadWebMapActivity ac = (LoadWebMapActivity)mContext;
            ac.onBackPressed();
        }
    }

    @JavascriptInterface
    public void hello(String params) {
        Toast.makeText(mContext, params, Toast.LENGTH_SHORT).show();
    }

    @JavascriptInterface
    public String getAndroid() {
        Toast.makeText(mContext, "getAndroid", Toast.LENGTH_SHORT).show();
        return "Android data";
    }

    @JavascriptInterface
    public String getAndroidTime() {
        return String.valueOf(System.currentTimeMillis());
    }

    @JavascriptInterface
    public void openVideoListActivity(){

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                mContext.startActivity(new Intent(mContext, RTMPActivity.class));

            }
        });
    }
}
